package com.yunhe.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;
import org.apache.jasper.tagplugins.jstl.core.ForEach;

import com.yunhe.bean.PageBean;
import com.yunhe.bean.UserTier;
import com.yunhe.inter.AdminDao;
import com.yunhe.inter.UserDaoImpl;
import com.yunhe.inter.UserService;
import com.yunhe.util.SqlSessionFactoryUtil;

/**
 * Servlet implementation class AdminSerlvet
 */
@WebServlet("/AdminSerlvet")
public class AdminSerlvet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	SqlSession sqlSession; 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminSerlvet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置接收值为UTF-8类型
		request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html");
		//页数
        int defaultPage=1;
		if(request.getParameter("currentPage")!=null){
			defaultPage=Integer.parseInt(request.getParameter("currentPage"));
		}
		PageBean pb=new PageBean();
		pb.setCurrentPage(defaultPage);
        UserService userservice=new UserDaoImpl();
        Map map=(Map)userservice.loadNews(pb);
        pb=(PageBean)map.get("pageBean");
		List<UserTier> list=(List<UserTier>) map.get("UserTier");
		request.setAttribute("list", list);
		request.setAttribute("PageBean", pb);
		request.getRequestDispatcher("manage/user.jsp").forward(request, response);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
